package com.unicloud.medical.oss.client;

import com.unicloud.medical.oss.client.selector.OssNameSelector;
import com.unicloud.medical.oss.common.ExtEndpoint;
import com.unicloud.medical.oss.common.model.BucketInfo;
import com.unicloud.medical.oss.common.model.DownloadObject;
import com.unicloud.medical.oss.common.model.ObjectInfo;
import com.unicloud.medical.oss.common.model.request.*;
import com.unisound.medical.common.model.dto.ResultDTO;
import org.springframework.http.ResponseEntity;

import java.util.List;

public class OSSClient extends OSSNameSelectorClient {

    private OssNameSelector defaultSelector;

    public OSSClient(ExtEndpoint extEndpoint, OssNameSelector defaultSelector) {
        super(extEndpoint);
        this.defaultSelector = defaultSelector;
    }

    /**
     * 查看存储桶是否存在
     */
    public ResultDTO<Boolean> defaultBucketExist(BucketExistRequest request) {
        return bucketExist(request, defaultSelector);
    }

    /**
     * 创建存储桶
     */

    public ResultDTO<Boolean> defaultCreateBucket(CreateBucketRequest request) {
        return createBucket(request, defaultSelector);
    }

    /**
     * 创建默认权限存储桶(默认策略支持浏览器直接访问url)
     */
    public ResultDTO<Boolean> defaultCreateDefaultPolicyBucket(CreateBucketRequest request) {
        return createDefaultPolicyBucket(request, defaultSelector);
    }

    /**
     * 删除存储桶
     */
    public ResultDTO<Boolean> defaultRemoveBucket(DeleteBucketRequest request) {
        return removeBucket(request, defaultSelector);
    }

    /**
     * 获取全部存储桶
     */
    public ResultDTO<List<BucketInfo>> defaultGetAllBuckets(CommonRequest request) {
        return getAllBuckets(request, defaultSelector);
    }

    /**
     * 获取当前存储桶所有文件
     */
    public ResultDTO<List<ObjectInfo>> defaultListAllObjectsCurrBucket(ListAllObjectsCurrBucketRequest request) {
        return listAllObjectsCurrBucket(request, defaultSelector);
    }

    /**
     * 获取当前存储桶当前文件夹所有文件
     */
    public ResultDTO<List<ObjectInfo>> defaultListObjectsCurrBucketAndFolder(ListAllObjectsCurrBucketAndFolderRequest request) {
        return listObjectsCurrBucketAndFolder(request, defaultSelector);
    }

    /**
     * 文件上传
     */
    public ResultDTO<List<String>> defaultUploadObjects(UploadObjectsRequest request) {
        return uploadObjects(request, defaultSelector);
    }

    /**
     * 批量本地文件上传
     */
    public ResultDTO<List<String>> defaultUploadLocalObjects(UploadLocalObjectsRequest request) {
        return uploadLocalObjects(request, defaultSelector);
    }

    public ResultDTO<DownloadObject> defaultDownloadObject(DownloadObjectRequest request) {
        request.setOssName(defaultSelector.select());
        return downloadObject(request);
    }

    /**
     * 文件下载
     */
    public ResponseEntity<byte[]> defaultDownloadObjectToBrowser(DownloadObjectRequest request) {
        request.setOssName(defaultSelector.select());
        return downloadObjectToBrowser(request);
    }

    public ResultDTO<DownloadObject> defaultDownloadObjects(DownloadObjectsRequest request) {
        request.setOssName(defaultSelector.select());
        return downloadObjects(request);
    }

    /**
     * 下载文件夹下所有文件
     */
    public ResponseEntity<byte[]> defaultDownloadObjectsToBrowser(DownloadObjectsRequest request) {
        request.setOssName(defaultSelector.select());
        return downloadObjectsToBrowser(request);
    }


    /**
     * 根据url地址删除文件
     */
    public ResultDTO<String> defaultRemoveObject(RemoveObjectRequest request) {
        return removeObject(request, defaultSelector);
    }

    /**
     * 根据url地址列表批量删除文件
     */
    public ResultDTO<List<String>> defaultRemoveObjects(RemoveObjectsRequest request) {
        return removeObjects(request, defaultSelector);
    }

    /**
     * 删除当前桶当前文件夹所有文件
     */
    public ResultDTO<List<String>> defaultRemoveObjects(RemoveObjectsCurrBucketAndFolderRequest request) {
        return removeObjects(request, defaultSelector);
    }

    /**
     * 文件复制
     */
    public ResultDTO<String> defaultCopyObject(CopyObjectRequest request) {
        return copyObject(request, defaultSelector);
    }

    /**
     * 已签名地址
     */
    public ResultDTO<String> defaultSignedUrl(SignedUrlRequest request) {
        return signedUrl(request, defaultSelector);
    }

    /**
     * 批量已签名地址
     */
    public ResultDTO<List<String>> defaultSignedUrls(SignedUrlsRequest request) {
        return signedUrls(request, defaultSelector);
    }

}
